<template>
  <div class="mine-box">
    <van-nav-bar
      title="usdt提现"
      left-arrow
      @click-left="onClickLeft"
      class="nav-bar"
    />
    <div class="mine-container">
      <van-row>
        <van-col span='24'>

          <div style="margin-top: 10px;">
            <van-row>
              <van-col class="_padding_l" span="6">地址名称：</van-col>
              <van-col style='color: #fff; font-size: 12px;line-height:20px;' span="18">例如 My Address #1,选填</van-col>
            </van-row>
          </div>
          <input class="inp_cont" placeholder="请输入提现地址" style="border-width:0;border-bottom-width:1px" v-model="address"/>
        </van-col>
      </van-row>
      <van-row>
        <div class='Rtitle'>
          <p class="_padding_l money_num" style="width:120px;
    display:inline;">提现金额量 :</p>
          <input class="money_tx" @keyup='moneyChange' placeholder="请输入提现金额" v-model="money">
        </div>
        <div class='Rtitle'>
          <p class="_padding_l money_num" style="width:120px;
    display:inline;">支付密码 :</p>
          <input type='password' class="money_tx" v-model="pad" placeholder="请输入密码">
        </div>
      </van-row>
      <van-row style="height:30px;">
        <p class="_padding_l money_num" style="width:120px;
            display:inline;">余额 : {{freeze}}</p>
      </van-row>
      <van-row style="height:30px;">
        <p class="_padding_l money_num" style="width:120px;
            display:inline;">手续费 : {{pay_money}}</p>
        <p class="_padding_l money_num" style="width:120px;
        display:inline;">实际到账 : {{get_money}}</p>
      </van-row>
    <van-button class="btn" type="warning" @click="putMoney">申请提现到地址</van-button>
    </div>
  </div>
</template>

<script>
  import { Button } from 'vant';
  import { Toast } from 'vant';
  import { Dialog } from 'vant';
  export default {
    data(){
      return {
      	address:'',
      	pad:'',
      	money:'',
        lastPageUrl:"",
        freeze:'',
        pay_money:"",
        get_money:""

      }
    },
    created(){

    },
    mounted(){
      this.lastPageUrl = sessionStorage.getItem("lastAndNowPage").split('-')[1];
      sessionStorage.setItem("lastAndNowPage",this.lastPageUrl+"-/Putforward");
      if(sessionStorage.getItem("usermessage")){
        token_g = JSON.parse(sessionStorage.getItem("usermessage")).token;
      }
      var $this = this;
      this.$axios({
             method: 'GET',
             url: url_g + '/asset/',
             headers: {
                  'Authorization': 'Bearer ' + token_g
              }
            }).then((res)=>{
                if(res && res.data && 0 < res.data.results.length){
                  res.data.results.map(function(item,index){
                    if(item.tk_code === "USDT"){
                      $this.freeze = parseFloat(item.total_qyt).toFixed(2)
                    }
                  })
                }
           }).catch((e) => {
              Toast(e.response.data.detail);
            });
            let cont = {
        type:'USDT_COMMISSION'
      }
      this.$axios({
        method: 'GET',
        url: url_g + '/config/',
        params: cont,
        headers: {
          'Authorization': 'Bearer ' + token_g
        }
      }).then((res) => {
        if(res && res.data && 0 < res.data.results.length){
          this.pay_money = res.data.results[0].value;
        }
      }).catch((e) => {
              Toast(e.response.data.detail);
      });
    },
    methods:{
      onClickLeft(){
        this.$router.push(this.lastPageUrl)
      },
      moneyChange(){
        if(this.money){
          this.get_money = parseFloat(this.money) - parseFloat(this.pay_money)
        }else{
          this.get_money = "";
        }
      },
    	putMoney(){
    		let $this = this
    		let cont = {
    			address:this.address,
    			qty:this.money,
    			pay_password:this.pad
    		}
    		if(cont.address==''){
				  Toast.fail('地址不能为空');
    		}else if(cont.qty==''){
				  Toast.fail('金额不能为空');
    		}else if(parseInt(cont.qty) < 50){
          Toast.fail('金额不能少于50');
        }else if(cont.pay_password==''){
				  Toast.fail('密码不能为空');
    		}else{
	    		 $this.$axios({
		       	 method: 'POST',
		         url: url_g + '/withdraw/',
		         data: cont,
             headers: {
                  'Authorization': 'Bearer ' + token_g
              }
		        }).then((res)=>{
    			Toast.success('提交成功');
		            this.address =''
	    			this.money =''
	    			this.pad =''
		       }).catch((e) => {
              Toast(e.response.data.detail);
		        });
    		}
    	}
    }
  }
</script>

<style scoped>
.mine-box{
  height: 100vh;
  background: -webkit-linear-gradient( top,#028aed,#273eec);
  color: #fff;
}
.mine-container {
  padding: 10px;
  width: calc(100% - 20px);
}
.nav-bar {
  color: #000;
}
.inp_cont{
	height: 30px;
	line-height: 30px;
	width: 96%;
	margin: 0 auto;
	display: block;
	margin-top: 10px;
	border: 1px solid #CCCCCC;
	padding: 3px;
  color: #000;
}
.Rtitle{
	color: #666666;
	margin-bottom: 5px;
}
.money_inp{
	height: 30px;
	line-height: 30px;
	width: 96%;
	margin: 0 auto;
	display: block;
	margin-top: 10px;
	border:none;
	border-bottom: 1px solid #CCCCCC;
	padding: 3px;
}
.btn{
	width: 90%;
	margin: 0 auto;
	display: block;
	margin-top: 40px;
}
.money_num{
	margin-top:30px;
	font-size: 16px;
	color: #fff;
}
.money_tx{
  width:calc(100% - 120px);
  float:right;
  border-top:0px;
  border-right:0px;
  border-left:0px;
  color: #000;
}
.Rtitle{
  margin-top:10px;
}
</style>
